<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>lodash按需加载 | 个人博客</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/timg.jpg">
    <meta name="description" content="个人博客,个人前端记录">
    
    <link rel="preload" href="/assets/css/0.styles.7229ef2a.css" as="style"><link rel="preload" href="/assets/js/app.801a065b.js" as="script"><link rel="preload" href="/assets/js/2.6771d448.js" as="script"><link rel="preload" href="/assets/js/12.77a531c8.js" as="script"><link rel="prefetch" href="/assets/js/10.3c75e5b5.js"><link rel="prefetch" href="/assets/js/11.c3b78bbf.js"><link rel="prefetch" href="/assets/js/13.0748fe31.js"><link rel="prefetch" href="/assets/js/14.1852ed44.js"><link rel="prefetch" href="/assets/js/15.0f8f0cd8.js"><link rel="prefetch" href="/assets/js/3.ac433df3.js"><link rel="prefetch" href="/assets/js/4.23cb9998.js"><link rel="prefetch" href="/assets/js/5.1e49aeaf.js"><link rel="prefetch" href="/assets/js/6.6538c0e6.js"><link rel="prefetch" href="/assets/js/7.1988c2bd.js"><link rel="prefetch" href="/assets/js/8.77c33b17.js"><link rel="prefetch" href="/assets/js/9.10721e21.js">
    <link rel="stylesheet" href="/assets/css/0.styles.7229ef2a.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/timg.jpg" alt="个人博客" class="logo"> <span class="site-name can-hide">个人博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="分类" class="dropdown-title"><span class="title">分类</span> <span class="arrow down"></span></button> <button type="button" aria-label="分类" class="mobile-dropdown-title"><span class="title">分类</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/folder1/test1.html" class="nav-link">
  文章
</a></li><li class="dropdown-item"><!----> <a href="/pages/folder2/test4.html" class="nav-link">
  琐碎
</a></li></ul></div></div><div class="nav-item"><a href="/pages/folder1/test3.html" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  功能演示
</a></div><div class="nav-item"><a href="https://github.com/dwanda" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="分类" class="dropdown-title"><span class="title">分类</span> <span class="arrow down"></span></button> <button type="button" aria-label="分类" class="mobile-dropdown-title"><span class="title">分类</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/folder1/test1.html" class="nav-link">
  文章
</a></li><li class="dropdown-item"><!----> <a href="/pages/folder2/test4.html" class="nav-link">
  琐碎
</a></li></ul></div></div><div class="nav-item"><a href="/pages/folder1/test3.html" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  功能演示
</a></div><div class="nav-item"><a href="https://github.com/dwanda" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>测试菜单1</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/folder1/test1.html" class="sidebar-link">子菜单1</a></li><li><a href="/pages/folder1/test3.html" aria-current="page" class="active sidebar-link">子菜单2</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/folder1/test3.html#lodash按需加载" class="sidebar-link">lodash按需加载</a></li></ul></li><li><a href="/pages/folder1/test6.html" class="sidebar-link">子菜单3</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h2 id="lodash按需加载"><a href="#lodash按需加载" class="header-anchor">#</a> lodash按需加载</h2> <p>https://www.jianshu.com/p/f03ff4f3a8b3</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>    <span class="token keyword">function</span> <span class="token function">reject</span><span class="token punctuation">(</span><span class="token parameter">reason</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">// reason失败态时接收的拒因</span>
        <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
            <span class="token comment">// 调用reject 回调对应onRejected函数</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>that<span class="token punctuation">.</span>status <span class="token operator">===</span> <span class="token constant">PENDING</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token comment">// 只能由pending状态 =&gt; rejected状态 (避免调用多次resolve reject)</span>
                that<span class="token punctuation">.</span>status <span class="token operator">=</span> <span class="token constant">REJECTED</span><span class="token punctuation">;</span>
                that<span class="token punctuation">.</span>reason <span class="token operator">=</span> reason<span class="token punctuation">;</span>
                that<span class="token punctuation">.</span>onRejectedCallbacks<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token parameter">cb</span> <span class="token operator">=&gt;</span> <span class="token function">cb</span><span class="token punctuation">(</span>that<span class="token punctuation">.</span>reason<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/pages/folder1/test1.html" class="prev">
        子菜单1
      </a></span> <span class="next"><a href="/pages/folder1/test6.html">
        子菜单3
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.801a065b.js" defer></script><script src="/assets/js/2.6771d448.js" defer></script><script src="/assets/js/12.77a531c8.js" defer></script>
  </body>
</html>
